package pkleczek.bugbrain;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuItem;

// FIXME: tytuły opcji nie wyświetlają się
// http://stackoverflow.com/questions/11048124/preferencescreen-and-edittextpreference-no-title

public class Settings extends PreferenceActivity {

	/**
	 * Checks that a preference is a valid numerical value
	 */
	Preference.OnPreferenceChangeListener numberCheckListener = new OnPreferenceChangeListener() {

		@Override
		public boolean onPreferenceChange(Preference preference, Object newValue) {
			// Check that the string is an integer.
			return newValue.toString().matches("\\d+");
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);

		getPreferenceScreen().findPreference("pref_neuron_threshold")
				.setOnPreferenceChangeListener(numberCheckListener);
		getPreferenceScreen().findPreference("pref_timing_bcpu")
				.setOnPreferenceChangeListener(numberCheckListener);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return super.onOptionsItemSelected(item);
	}

}
